package org.gestorTareas.actions.interceptors;

import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.apache.struts2.ServletActionContext;
import org.gestorTareas.model.dao.HibernateDao;
import org.gestorTareas.model.dao.UsuarioDao;
import org.gestorTareas.model.dto.Usuario;
import org.gestorTareas.utils.IConstants;
import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.interceptor.Interceptor;

public class SecureLoginInterceptor implements Interceptor {

	public String intercept(ActionInvocation invocation) throws Exception {

		Map session = invocation.getInvocationContext().getSession();
		
		Object usuario = session.get(IConstants.USER_SESSION);
		if (usuario == null) {
			return ActionSupport.LOGIN;
		} else {
			return invocation.invoke();
		}
	}

	public void destroy() {
		System.out.println("Destroying MyLoggingInterceptor...");
	}

	public void init() {
		System.out.println("Initializing MyLoggingInterceptor...");
	}

}
